package com.hsmw.api.controller.pub;


import com.alibaba.fastjson.JSON;
import com.hsmw.api.vo.WebSocketReturnVO;
import com.htn.common.core.constant.WebsocketTypeEnum;
import com.htn.common.core.utils.StringUtils;
import com.tencent.xinge.XingeApp;
import com.tencent.xinge.bean.*;
import com.tencent.xinge.push.app.PushAppRequest;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Vector;
import java.util.ArrayList;

public class TencentPushUtils {
    private static  final String  TARGET_URL = "https://api.tpns.sh.tencent.com/";
    private static  final String  DRIVER_SECRET_KEY = "8565367c5c9c616046dc72c7f2212bef";
    private static  final String  DRIVER_APP_ID = "1580003766";

    private static  final String  FOREMAN_SECRET_KEY = "75258f3f4d57c4ee89da4e25de93f0ec";
    private static  final String  FOREMAN_APP_ID = "1580006524";

    private static  final String  SELFRUN_SECRET_KEY = "13ea9e2e082d3d61af380489ba4c70b7";
    private static  final String  SELFRUN_APP_ID = "1580007292";

    //司机推送的实例
    static XingeApp xingeDriverApp = new XingeApp.Builder()
            .appId(DRIVER_APP_ID)
            .secretKey(DRIVER_SECRET_KEY).domainUrl(TARGET_URL).build();

    //工长推送的实例
    static XingeApp xingeForemanApp = new XingeApp.Builder()
            .appId(FOREMAN_APP_ID)
            .secretKey(FOREMAN_SECRET_KEY).domainUrl(TARGET_URL).build();

    //工长推送的实例
    static XingeApp xingeSelfrunApp = new XingeApp.Builder()
            .appId(SELFRUN_APP_ID)
            .secretKey(SELFRUN_SECRET_KEY).domainUrl(TARGET_URL).build();

    private static  final String  FM_TARGET_URL = "";
    private static  final String  FM_SECRET_KEY = "";
    private static  final String  FM_APP_ID = "";



    public static JSONObject pushMsg(String content,String account,String ringRaw){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        messageAndroid.setRing_raw(ringRaw);
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeDriverApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }


    public static JSONObject pushForeManMsg(String content,String account,String ringRaw){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        messageAndroid.setRing_raw(ringRaw);
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeForemanApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }


    public static JSONObject selfrunMsg(String content,String account,String ringRaw){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        if(StringUtils.isNotBlank(ringRaw)){
            messageAndroid.setRing_raw(ringRaw);
        }
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeForemanApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }


    public static JSONObject selfrunCanCelMsg(String content,String account,String ringRaw,WebSocketReturnVO webSocketReturnVO){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        messageAndroid.setRing_raw(ringRaw);
        messageAndroid.setCustom_content(JSON.toJSONString(webSocketReturnVO));
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeForemanApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }


    public static JSONObject pushCancelForeManMsg(String content,String account,String ringRaw,WebSocketReturnVO webSocketReturnVO){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        messageAndroid.setRing_raw(ringRaw);
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeForemanApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }



    public static JSONObject htnPushInviteMsg(String content,String account,WebSocketReturnVO webSocketReturnVO){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        messageAndroid.setCustom_content(JSON.toJSONString(webSocketReturnVO));
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeForemanApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }

    public static JSONObject htnPushDriverMsg(String content,String account,WebSocketReturnVO webSocketReturnVO){
        PushAppRequest pushAppRequest = new PushAppRequest();
        pushAppRequest.setAudience_type(AudienceType.account);
        pushAppRequest.setPlatform(Platform.android);
        pushAppRequest.setMessage_type(MessageType.notify);
        pushAppRequest.setAccount_push_type(0);
        Message message = new Message();
        message.setTitle("通知：");
        message.setContent(content);
        message.setContentDefault("qeqweqwewqe");
        MessageAndroid messageAndroid = new MessageAndroid();
        messageAndroid.setCustom_content(JSON.toJSONString(webSocketReturnVO));
        message.setAndroid(messageAndroid);
        pushAppRequest.setMessage(message);
        ArrayList<String> accountList = new ArrayList();
        accountList.add(account);
        pushAppRequest.setAccount_list(accountList);
        JSONObject result = xingeDriverApp.pushApp(pushAppRequest);
        System.out.println(result.toString());
        return result;
    }







    public static void main(String[] args) {

        WebSocketReturnVO webSocketReturnVO = new WebSocketReturnVO();

        webSocketReturnVO.setRelationId("HTN2021120109y5y04662");
        TencentPushUtils.selfrunCanCelMsg("已完成作业，请及时做出评价", "13212040676", "has_new_message", webSocketReturnVO);

    }







}
